package com.baidu.health.service.impl;

import com.baidu.health.pojo.ResultResponse;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baidu.health.pojo.TbAnswer;
import com.baidu.health.service.TbAnswerService;
import com.baidu.health.mapper.TbAnswerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 *
 */
@Service
public class TbAnswerServiceImpl extends ServiceImpl<TbAnswerMapper, TbAnswer>
    implements TbAnswerService{
    @Autowired
    private TbAnswerMapper tbAnswerMapper;
    @Override
    public ResultResponse answerSelect(Integer askId) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("ask_id",askId);
        List<TbAnswer> list = tbAnswerMapper.selectList(queryWrapper);
        return ResultResponse.SUCCESS(list);
    }

    @Override
    public ResultResponse answerInsert(TbAnswer tbAnswer) {
        tbAnswer.setCreateTime(new Date());
        tbAnswerMapper.insert(tbAnswer);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse answerUpdate(TbAnswer tbAnswer) {
        tbAnswerMapper.updateById(tbAnswer);
        return ResultResponse.SUCCESS();
    }

    @Override
    public ResultResponse answerDeleted(Integer answerId) {
        tbAnswerMapper.deleteById(answerId);
        return ResultResponse.SUCCESS("删除成功");
    }
}




